package com.ruoyi.tools.util.param;

public class DomainReplace {


    public static String replacePlaceholders(String str, String[] placeholders, String replacement) {
        boolean replaced = false; // 用于跟踪是否已经执行了替换
        // 循环遍历需要替换的字符串数组
        for (String placeholder : placeholders) {
            if (str.contains(placeholder)) { // 检查是否存在需要替换的占位符
                str = str.replace(placeholder, replacement);
                replaced = true; // 替换成功
                break; // 终止循环
            }
        }
        return str;
    }

    public static void main(String[] args) {
        String str = "Hello, [name]! Today is [day].";
        String[] placeholders = {"[name]", "[day]"};
        String replacement = "John Doe";

        String replacedStr = replacePlaceholders(str, placeholders, replacement);
        System.out.println(replacedStr);
    }
}
